

namespace Nadine
{
	//-------------------------------------------------------------
	class NDCHCSPOcclusionQuery :public NDBaseObject
	{
		friend class NDCHCSPQueryHandler;

	private:
		std::vector< sCHCSPNode* > 	m_arrNodes;
		UINT				  		m_nQueryId;
		NDW32OSInterface*	 		m_pNDW32OS;

	protected:
		explicit NDCHCSPOcclusionQuery(NDArk* pArk, UINT nID) : NDBaseObject(99), m_nQueryId(nID)
		{
			this->setArk(pArk);
			this->m_pNDW32OS =NDW32OS;
		}

	public:
		explicit NDCHCSPOcclusionQuery(NDArk* pArk);

		virtual ~NDCHCSPOcclusionQuery()
		{
			assert( m_arrNodes.size() ==0);
		}

		virtual void release();

		bool	ResultAvailable() const;
		UINT	GetQueryResult() const;

		void	BeginQuery() const;
		void	EndQuery() const;

		UINT	GetQueryId() const;

		sCHCSPNode*	GetFrontNode() const		{ return m_arrNodes[0]; }
		const	std::vector< sCHCSPNode* >& GetNodes() const { return m_arrNodes; }

		void 	Reset()							{ m_arrNodes.clear(); }
		void	AddNode(sCHCSPNode* pNode)		{ m_arrNodes.push_back( pNode ); }
		int		GetSize() const					{ return (int)m_arrNodes.size(); }


	};
	typedef std::queue< NDCHCSPOcclusionQuery* >  NDCHCSPQueryQueue;
	typedef std::vector< NDCHCSPOcclusionQuery* > NDCHCSPQueryContainer;


	//-------------------------------------------------------------
	class NDCHCSPQueryHandler :public NDBaseObject
	{
	private:
		int 					m_nCurrentQueryIdx;
		NDCHCSPQueryContainer 	m_arrOcclusionQueries;

	protected:
		void Allocate(int n);		/** allocates n queries in advance*/

	public:
		explicit NDCHCSPQueryHandler(NDArk* pArk);
		virtual ~NDCHCSPQueryHandler()
		{
			assert( m_arrOcclusionQueries.empty() );
		}

		virtual void 			release();

		NDCHCSPOcclusionQuery* 	RequestQuery();

		void 					ResetQueries();		/** Must be called every frame.*/
		void 					DestroyQueries();	/** Destroys all the queries.*/

	};



}